<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="auth" uri="http://www.jiyinit.com/authTag"%>

<head>
    <link rel="stylesheet" href="${basePath}/assets/css/foundation-datepicker.css"/>
</head>

<div class="right-container">
    <div class="container-select text-left">
        <div class="search-input" >
            <span >标题：</span>
            <input id="noticeTitle" name="noticeTitle" type="text">
        </div>
        <div class="search-input"  >
            <span >发布时间从：</span>
                <input class="date-icon" type="text" id="startTime" name="startTime"  />

        </div>
        <div class="search-input" >
            <label >到：</label>
                <input class="date-icon" type="text" id="endTime" name="endTime"  />
        </div>

        <auth:auth authUrl="notice/findByPage">
            <button id="searchBtn" class="btn btn-primary" type="button">
                <i class="fa fa-search"></i> 查询
            </button>
        </auth:auth>
    </div>

    <div class="manage-button text-left">
        <auth:auth authUrl="notice/toRead">
            <button id="readBtn" class="btn btn-primary" type="button">
                <i class="fa fa-building"></i> 查看消息的读取情况
            </button>
        </auth:auth>

        <auth:auth authUrl="notice/toAdd">
            <button id="addBtn" class="btn btn-primary" type="button">
                <i class="fa fa-plus"></i>&nbsp;新增
            </button>
        </auth:auth>
    </div>




    <div class="row">
        <div class="col-xs-12">
            <table id="grid-table"></table>
            <div id="grid-pager"></div>
        </div>
    </div>
</div>

<!-- page specific plugin scripts -->
<script src="${basePath}/plugins/jqGrid/jquery.jqGrid.min.js${VERSION}"></script>
<script src="${basePath}/plugins/jqGrid/grid.locale-cn.js${VERSION}"></script>
<script src="${basePath}/assets/js/foundation-datepicker.js"></script>

<!-- inline scripts related to this page -->
<script type="text/javascript">

    var pageii = null;
    jQuery(function ($) {
        $('.date-icon').fdatepicker({
            format: 'yyyy-mm-dd'
        });
       /* $('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
            $(this).prev().focus();
        });*/
        CommonUtils.grid({
            url: "${basePath}/notice/findByPage",
            colNames: ['ID','标题', '优先级', '创建人ID', '创建时间', '修改人ID', '修改时间'],
            colModel: [
                {name: 'noticeId', index: 'noticeId', key: true, width: 20, sorttype: "int"},
                {name: 'noticeTitle', index: 'noticeTitle', width: 50},
                {name: 'priority', index: 'priority', width: 80, formatter: CommonUtils.priority},
                {name: 'createName', index: 'createName', width: 20},
                {name: 'createTime', index: 'createTime', width: 50, formatter: CommonUtils.formateDate},
                {name: 'lastModifyName', index: 'lastModifyName', width: 20},
                {name: 'lastModifyTime', index: 'lastModifyTime', width: 50, formatter: CommonUtils.formateDate}
            ]
        });

        $("#searchBtn").click(function () {
            query();
        });

        function query() {
            var queryData = {
                "title": $.trim($('#noticeTitle').val()),
                "startTime": $.trim($('#startTime').val()),
                "endTime": $.trim($('#endTime').val())
            };
            $("#grid-table").jqGrid("setGridParam", {
                postData: queryData
            }
            ).trigger("reloadGrid", [{page: 1}]);
        };

        $("#readBtn").click("click", function () {
            var rowId = $("#grid-table").jqGrid('getGridParam', 'selarrrow');
            if (rowId.length > 1 || rowId == "") {
                layer.msg("请选择一行数据进行查看！");
                return;
            }
            var rowData = $("#grid-table").jqGrid('getRowData', rowId);
            var id = rowData.noticeId;

            pageii = layer.open({
                title: "查询",
                type: 2,
                area: ["600px", "500px"],
                content: '${basePath}/notice/toRead?noticeId=' + id
            });

        });

        $("#addBtn").click("click", function () {
            if ($(window).width() > 1000){
                pageii = layer.open({
                    title: "新增通知",
                    type: 2,
                    maxmin: true,
                    area: ["1000px", "90%"],
                    content: ['${basePath}/notice/toAdd']
                });
            }
            else{
                pageii = layer.open({
                    title: "新增通知",
                    type: 2,
                    maxmin: true,
                    area: ["80%", "90%"],
                    content: ['${basePath}/notice/toAdd']
                });
            }


        });

    });
</script>
